﻿<Window x:Class="MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:RegexUtility"
        Title="Regex Utility"
        Height="350"
        Width="525"
        DataContext="{Binding RelativeSource={RelativeSource Mode=Self}}">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <Menu>
            <MenuItem Header="File">
                <MenuItem Header="Save"
                          Command="{Binding SaveFile}" />
                <MenuItem Header="Open"
                          Command="{Binding OpenFile}" />
            </MenuItem>
        </Menu>

        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <TextBlock Text="Expression"
                       Margin="4,2"
                       VerticalAlignment="Center" />

            <TextBox x:Name="SinglelineEditorTextBox"
                     Grid.Column="1"
                     AcceptsReturn="True"
                     AcceptsTab="True"
                     HorizontalScrollBarVisibility="Auto"
                     VerticalScrollBarVisibility="Auto"
                     Margin="4,2,0,2"
                     Text="{Binding RegexPattern}" />

            <!--<Popup PlacementTarget="{Binding ElementName=SinglelineEditorTextBox}"
                   Placement="Bottom"
                   IsOpen="{Binding Path=IsChecked, ElementName=ShowMultilineEditorToggleButton, Mode=TwoWay}"
                   StaysOpen="False"
                   Grid.Column="1"
                   Width="{Binding Path=ActualWidth, ElementName=SinglelineEditorTextBox}">
                <TextBox Text="{Binding RegexPattern}"
                         AcceptsReturn="True"
                         AcceptsTab="True"
                         Height="200"
                         HorizontalScrollBarVisibility="Auto"
                         VerticalScrollBarVisibility="Auto" />
            </Popup>

            <ToggleButton x:Name="ShowMultilineEditorToggleButton"
                          Grid.Column="2"
                          Margin="0,2,4,2">
                <Path Stroke="{Binding Path=BorderBrush, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ToggleButton}}}"
                      StrokeLineJoin="Miter"
                      Fill="{Binding Path=BorderBrush, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ToggleButton}}}">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="0,0"
                                        IsClosed="True">
                                <LineSegment Point="8,0" />
                                <LineSegment Point="4,4" />
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
            </ToggleButton>-->

            <ToggleButton x:Name="ShowOptionsToggleButton"
                          Grid.Column="3"
                          Margin="4,2"
                          VerticalAlignment="Center">
                <ToggleButton.Style>
                    <Style TargetType="{x:Type ToggleButton}">
                        <Setter Property="Content"
                                Value="Show Options" />
                        <Style.Triggers>
                            <Trigger Property="IsChecked"
                                     Value="True">
                                <Setter Property="Content"
                                        Value="Hide Options" />
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </ToggleButton.Style>
            </ToggleButton>

            <!--<Popup Grid.Column="2"
                   IsOpen="{Binding ElementName=OptionsToggleButton, Path=IsChecked}"
                   PlacementTarget="{Binding ElementName=OptionsToggleButton}"
                   Placement="Bottom">
                <Border Background="White">
                    
                </Border>
            </Popup>-->

        </Grid>

        <UniformGrid Grid.Row="2"
                     Visibility="{Binding ElementName=ShowOptionsToggleButton, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}">
            <CheckBox Content="Compiled"
                      IsChecked="{Binding IsCompiled}"
                      Margin="4,2" />
            <CheckBox Content="Culture Invariant"
                      IsChecked="{Binding IsCultureInvariant}"
                      Margin="4,2" />
            <CheckBox Content="ECMA Script"
                      IsChecked="{Binding IsEcmaScript}"
                      Margin="4,2" />
            <CheckBox Content="Explicit Capture"
                      IsChecked="{Binding IsExplicitCapture}"
                      Margin="4,2" />
            <CheckBox Content="Ignore Case"
                      IsChecked="{Binding IsIgnoreCase}"
                      Margin="4,2" />
            <CheckBox Content="Ignore Pattern Whitespace"
                      IsChecked="{Binding IsIgnorePatternWhitespace}"
                      Margin="4,2" />
            <CheckBox Content="Multiline"
                      IsChecked="{Binding IsMultiline}"
                      Margin="4,2" />
            <CheckBox Content="Right To Left"
                      IsChecked="{Binding IsRightToLeft}"
                      Margin="4,2" />
            <CheckBox Content="Singleline"
                      IsChecked="{Binding IsSingleline}"
                      Margin="4,2" />
        </UniformGrid>

        <TabControl Grid.Row="3"
                    Margin="4"
                    SelectedIndex="{Binding SelectedSearchMode}">
            <TabControl.Style>
                <Style>

                </Style>
            </TabControl.Style>

            <TabItem Header="Sample Input">
                <TextBox Text="{Binding SampleInput}"
                         AcceptsReturn="True"
                         AcceptsTab="True"
                         HorizontalScrollBarVisibility="Auto"
                         VerticalScrollBarVisibility="Auto"
                         TextWrapping="NoWrap" />
            </TabItem>

            <TabItem Header="Find in Files">
                <Grid>

                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition />
                    </Grid.RowDefinitions>

                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>

                        <TextBlock Text="Folder"
                                   Margin="4,2"
                                   VerticalAlignment="Center" />

                        <TextBox Text="{Binding FindInFilesFolder, UpdateSourceTrigger=PropertyChanged}"
                                 Grid.Column="1"
                                 Margin="4,2"
                                 VerticalAlignment="Center" />

                        <Button Content="Browse..."
                                Command="{Binding Browse}"
                                Grid.Column="2"
                                Margin="4,2"
                                VerticalAlignment="Center" />

                        <CheckBox Content="Include Sub-Folders"
                                  IsChecked="{Binding SearchInSubFolders}"
                                  Grid.Column="3"
                                  Margin="4,2"
                                  VerticalAlignment="Center" />

                    </Grid>

                    <Grid Grid.Row="1">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>

                        <TextBlock Text="File Name Filter (RegEx)"
                                   Margin="4,2"
                                   VerticalAlignment="Center" />

                        <TextBox Text="{Binding FileNameFilter, UpdateSourceTrigger=PropertyChanged}"
                                 Grid.Column="1"
                                 Margin="4,2"
                                 VerticalAlignment="Center" />
                    </Grid>

                    <ListBox ItemsSource="{Binding FileNameFilterResults}"
                             Grid.Row="2"
                             Margin="4">

                    </ListBox>

                </Grid>
            </TabItem>

        </TabControl>

        <Grid Grid.Row="4">

            <Button Content="Execute RegEx"
                    Command="{Binding ExecuteRegex}"
                    HorizontalAlignment="Right"
                    Margin="4,2"
                    Width="120" />

        </Grid>

    </Grid>
</Window>
